//事件冒泡：事件作用在那个元素身上就会冒出来
$(".B").mouseenter(function(){
    $(this).css("background-color"," red");
  });
  $(".B").mouseleave(function(){
    $(this).css("background-color","gainsboro");
  });
// -----------------------购物车加
document.querySelector(".G").onclick=function(event){
 var ele=event.target;
 console.log(ele.nodeName)
 if(ele.nodeName =='BUTTON' && ele.innerText=="+"){
  var count=ele.previousElementSibling.value;
  ele.previousElementSibling.value=++count;
    console.log("数量："+count)
 }
}
// ----------------------------购物车减
document.querySelector(".G1").onclick=function(event){
  var ele=event.target;
  console.log(ele.nodeName)
  if(ele.nodeName =='BUTTON' && ele.innerText=="-"){
    if(ele.previousElementSibling.previousElementSibling.value>1){
   var count=ele.previousElementSibling.previousElementSibling.value;
  //  console.log("数量："+count)
  ele.previousElementSibling.previousElementSibling.value=--count;
     console.log("数量："+count)
    }
  }
 }
//  ----------------------------关注
document.querySelector(".love").onmouseover=function(){
  var arr =document.querySelector(".love").children
 arr[0].src="../images/detail_love1.svg"
 if(document.querySelector(".follow").onclick)
 var arr =document.querySelector(".follow").previousElementSibling.children
 arr[0].src="../images/detail_love1.svg"
}
document.querySelector(".love").onmouseout=function(){
  var arr =document.querySelector(".love").children
 arr[0].src="../images/detail_love.svg"
}
document.querySelector(".follow").onclick=function(){
  var arr =document.querySelector(".follow").previousElementSibling.children
  arr[0].src="../images/detail_love1.svg"
  return false
}
// --------------------------------商品介绍
$(".C").mouseenter(function(){
  $(this).css("background-color","red");
});
$(".C").mouseleave(function(){
  $(this).css("background-color"," gainsboro");
});
// ----------------------------------选择尺寸
$(".Dt").focus(function(){
  $(this).css("background-color"," #f3f3f3");
});
$(".Dt").blur(function(){
  $(this).css("background-color"," #fff");
});
// ---------------------------------选择图片
$(".Ca").click(function(){
  $(this).css("color","red");
  console.log("A")
});
$(".Ca").blur(function(){
  $(this).css("color","#666");
});

//加入购物车
$(".buy").click(function (){
    var token=localStorage.getItem("token")
    $.ajax({
        type:"post",
        url:"http://localhost:8081/demo/cart/addToCart",
        async: false,
        headers:{"token":token},
        data:{
            productId:$(".proId").val(),
            productNum:$(".car-value").val()
        },
        success:function(result){
            console.log(result);
            if (result.data !=null){
                alert("添加成功");
            }else{
                alert("添加失败，请重新添加");
            }
        },dataType:'json'
    })
})

/*===== 立即购买 ======*/
$(".buynow").click(function (){
    var token = localStorage.getItem("token");
    var id = $(".proId").val();
    var productNum=$(".car-value").val()
    proId = parseInt(id);
    proId +=1000;
    $(this).attr("href","http://localhost:8081/demo/spikeProduct/goConfirm?proId="+proId+"&token="+token);
})